package com.lanzuo.pana.adapter.client.filter;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import com.lanzuo.adapter.common.constant.CommandConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.mina.core.session.IoSession;

/**
 * @author eric
 * 心跳
 */
@Slf4j
public class Heartbeat {

    public static void send(IoSession session) {
        if (session.containsAttribute("machineCode")) {
            String heartbeat = StrUtil.format(CommandConstant.PING_TEMPLATE, session.getAttribute("machineCode"), RandomUtil.randomString(10));
            session.write(heartbeat);
        }

    }

}